function HandlePageB1DeleteOrder(gui, operator, now, options) {
  this._gui = gui;
  this._operator = operator;
  this._now = now;
  this._options = options;
  this._popupBox = new PopupBox();
  this._cond = ' o.admAppr = 0';
  this._type = '{{$smarty.const.APPROVE_TYPE_NOTAPPROVED|escape:javascript}}';
  
  this._createElements();
};

HandlePageB1DeleteOrder.prototype._createElements = function() {
  var tr, td,_self = this;
  tr = this._gui.main.insertRow(-1);
  td = tr.insertCell(-1);
  td.appendChild(DOMUtils.getLoadingImage());
  
  for (var i = 0, il = ApproveType.array().length; i < il; i++) {
    var type = ApproveType.array()[i];
    option = new Option(type);
    this._gui.display.options[this._gui.display.options.length] = option;
    if (option.text == this._type) {
      this._gui.display.selectedIndex = this._gui.display.options.length - 1;
    }
  }
  
  this._gui.display.onchange = function() { _self._type = this.options[this.selectedIndex].text;
                                            if (_self._type == '{{$smarty.const.APPROVE_TYPE_NOTAPPROVED|escape:javascript}}') {
                                              _self._cond = ' o.admAppr = 0';
                                            } else {
                                              _self._cond = null;
                                            }
                                            _self._retrieveOrders(1);
                                          };
  this._loadData();
};

HandlePageB1DeleteOrder.prototype._loadData = function() {
  this._orders = null;
  this._parameters = null;
  this._retrieveOrders(1);
};

HandlePageB1DeleteOrder.prototype._verifyData = function() {
  if (this._orders) {
    this._updateElements();
  }
};

HandlePageB1DeleteOrder.prototype._retrieveOrders = function(page) {
  var _self = this;
  var args = ((this._cond) ? '&c=' + this._cond : '') + '&p=' + page + '&s=20';
  new RequestUtils()._mysql('deleteorder', args, function(result, params) { _self._orders = result.data;
                                                                            _self._parameters = result;
                                                                            _self._verifyData.call(_self);
                                                                          }, null);
};

HandlePageB1DeleteOrder.prototype._updateElements = function() {
  var tr, td, _self = this, unique = MiscUtils.unique();
  DOMUtils.removeTableRows(this._gui.main, 1);
  DOMUtils.removeChildElements(this._gui.page);
  DOMUtils.removeChildElements(this._gui.checkAll);
  this._selects = [];
  this._gui.approve.onclick = function() { if (_self._selects.length == 0) {
                                            window.alert('No Items Selected');
                                            return;
                                           }
                                           var objects = [];
                                           for(var i = 0, il = _self._selects.length; i < il; i++) {
                                             var object = _self._selects[i];
                                             objects[objects.length] = object.id;
                                           }
                                           new RequestUtils()._mysql('approveorder', '&o=' + JSON.stringify(objects), function(result, params) { _self._retrieveOrders(_self._parameters.page); }, { pos: DOMUtils.findPos(this) });
                                         };
  
  if (this._orders.length == 0) {
    tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.height = '24px';
    td.style.textAlign = 'center';
    td.colSpan = 5;
    td.style.backgroundColor = '#fff';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.appendChild(document.createTextNode('N/A'));
  }
  
  for(var i = 0, il = this._orders.length; i < il; i++) {
    var o = this._orders[i];
    tr = this._gui.main.insertRow(-1);
    tr.style.backgroundColor = (tr.rowIndex % 2 == 0) ? '#faf9f4' : '#ffffff';
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    var check = DOMUtils.createInput('', unique + '_' + i, 'checkbox', '', null);
    check._o = o;
    check.onclick = function() { if (this.checked == true) {
                                   _self._selects[_self._selects.length] = this._o;
                                 } else {
                                   MiscUtils.remove(_self._selects, this._o, 'trackId');
                                 }
                               };
    if (o.admAppr == 0) {
      td.appendChild(check);
    }
    

    td = tr.insertCell(-1);
    td.style.padding = '0 0 0 10px';
    td.style.height = '25px';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    var a = document.createElement('a');
    a.href = '#';
    a._c = o;
    a.appendChild(document.createTextNode(DlmanageUtils.customerId(o.customerId) + o.flag));
    a.onclick = function() {location.href = '?p=pageadmin&t=pagecustomerold&m=' + JSON.stringify({ a: 2, b: 1 }) + '&opts=' + JSON.stringify({ id: this._c.customerId, track: this._c.trackId, isAdmin: true }); return false;};
    td.appendChild(a);

    td = tr.insertCell(-1);
    td.style.textAlign = 'center';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.appendChild(document.createTextNode( SimpleDate.format(o.cancelledDate)));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.paddingLeft = '10px';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    td.appendChild(document.createTextNode(o.cancelledOperator));
    
    td = tr.insertCell(-1);
    td.style.textAlign = 'left';
    td.style.paddingLeft = '10px';
    td.style.borderRight = 'solid 1px #694247';
    td.style.borderBottom = 'solid 1px #694247';
    if (o.cancelledMessage && o.cancelledMessage.length == 0) {
      td.appendChild(document.createTextNode('(None)'));
    }
    td.appendChild(document.createTextNode(o.cancelledMessage ? ((o.cancelledMessage.length > 100) ? o.cancelledMessage.substring(0, 100) + '...' : o.cancelledMessage) : '(None)'));
    if (o.cancelledMessage && o.cancelledMessage && o.cancelledMessage.length > 100) {
      var a = document.createElement('a');
      a.href = '#';
      a._o = o;
      a.appendChild(document.createTextNode('All'));
      a.onclick = function() { var pos, func1, func2;
                                var pos = DOMUtils.findPos(this);
                                var div = document.createElement('div');
                                func1 = function() { _self._popupBox._close();
                                                   };
                                div.appendChild(MiscUtils.span(this._o.cancelledMessage));
                                MiscUtils.dialog(_self._popupBox, pos, div, func1, null);
                                return false;
                              };
      td.appendChild(a);
    }
  }
  
  this._gui.checkAll.checked = false;
  this._gui.checkAll._unique = unique;
  this._gui.checkAll.onclick = function() { if (this.checked == true) {
                                             for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i) && !document.getElementById(this._unique + '_' + i).checked) {
                                                  _self._selects[_self._selects.length] = object;
                                                  document.getElementById(this._unique + '_' + i).checked = true;
                                                }
                                              }
                                            } else {
                                              for (var i = 0, il = _self._orders.length; i < il; i++) {
                                                var object = _self._orders[i];
                                                if (document.getElementById(this._unique + '_' + i)) {
                                                  MiscUtils.remove(_self._selects, object, 'trackId');
                                                  document.getElementById(this._unique + '_' + i).checked = false;
                                                }
                                              }
                                            }
                                          };
  
  
  /*--PAGINATION--*/
  Pagination.makePagedResults(this._gui.page, this._parameters.page, this._parameters.total, this._parameters.size, function(page, condition) { _self._retrieveOrders.call(_self, page, _self._parameters.condition); }, this, document);
};

